feat(root): refactor root access - #107
Conversation
step 1 restore outdated and buggy old root code
|
Currently running the debug build :). Can confirm that this works. Thanks :) |
|
Currently the "Run Script" feature does not work as the scripts ion ".stfolder" are likely not accessible due to permission issues. Would it be possible to fix this? |
pls look at util.runScriptSet and runShellCommandGetOutput(command, false).. if you set true you will get root exec of the scripts needs secure and proper implementation tbh for being accepted here and file permissions should be checked before |
|
@dbhavsar76 may i kindly ask if you like to have fun with this?? it is also ok for me if you dont take the challenge |
|
I'll see what i can do. No promises. Meanwhile, I have the drawer ready. |
There was a problem hiding this comment.
Pull request overview
This PR refactors the app’s “run Syncthing as root” support by introducing a root capability check, adding a user-facing root toggle in settings, and updating service/runtime behavior to execute process management and permission-repair steps with root where appropriate.
Changes:
- Add
RootAccesshelper and a new “Run Syncthing as Superuser” preference, wiring it into the settings UI and runtime startup logic. - Adjust shell-command helpers and Syncthing process management to optionally execute via
su, including environment setup when launching Syncthing under root. - Attempt to repair app data permissions/SELinux contexts when config read/write fails (to recover from prior root-owned files).
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| gradle/libs.versions.toml | Adds libsuperuser version + catalog entry for root availability checks. |
| app/build.gradle.kts | Adds the libsuperuser dependency to the app module. |
| app/src/main/res/values/strings.xml | Adds user-facing strings for root toggle + root denial toast. |
| app/src/main/java/com/nutomic/syncthingandroid/util/Util.java | Adds permission-fix helper and root-capable shell execution helpers. |
| app/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java | Attempts permission repair before failing config parse/save due to access issues. |
| app/src/main/java/com/nutomic/syncthingandroid/settings/SettingsBehaviorScreen.kt | Adds UI switch to enable/disable root mode and restarts service on change. |
| app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingService.java | Stops treating use_root as deprecated during pref import. |
| app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingRunnable.java | Runs process discovery/kill and syncthing launch via root when enabled. |
| app/src/main/java/com/nutomic/syncthingandroid/service/Constants.java | Introduces PREF_USE_ROOT constant. |
| app/src/main/java/com/nutomic/syncthingandroid/root/RootAccess.java | New helper for blocking root availability check via libsuperuser. |
| app/src/main/java/com/nutomic/syncthingandroid/receiver/BootReceiver.java | Kills leftover SyncthingNative after app update when running in root mode. |
Suppressed comments (1)
app/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java:1267
- Same pattern as in
parseConfig(): after attemptingfixAppDataPermissions(), re-check writability before proceeding, otherwise the method may continue and fail later when trying to write the temp file/rename, while the log suggests the permission issue was handled.
if (!mConfigFile.canWrite() && !Util.fixAppDataPermissions(mContext)) {
Log.w(TAG, "Failed to save updated config. Cannot change the owner of the config file.");
return;
}
2debb5a to
fb0b138
Compare
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Jonas <244199422+researchxxl@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.